package com.youhome.business.controller;

import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.service.model.BLog;
import com.youhome.service.model.BUser;
import com.youhome.service.model.Principal;
import com.youhome.service.response.DateValue;
import com.youhome.service.service.BCompanyService;
import com.youhome.service.service.BUserService;
import com.youhome.service.service.DateAnalysisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by chen365 on 2018/1/2.
 */
@RestController
@RequestMapping(value = "/data/analysis/stat")
@Api(tags = "数据分析")
public class DataAnalysisController {

    @Autowired
    private DateAnalysisService dateAnalysisService;

    @ApiOperation(value = "短信每天发送统计", notes = "短信每天发送统计", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Date", name = "btime", value = "开始时间", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Date", name = "etime", value = "结束时间", required = true, paramType = "query")
    })
    @GetMapping(value = "/sms")
    public Object sms(Date btime, Date etime, @ApiIgnore @AuthenticationPrincipal Principal principal) throws CustomException {
        return new Result(ResultCode.SUCCESS, dateAnalysisService.statSMSByDate(principal, btime, etime));
    }

    @ApiOperation(value = "邮件每天发送统计", notes = "邮件每天发送统计", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Date", name = "btime", value = "开始时间", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Date", name = "etime", value = "结束时间", required = true, paramType = "query")
    })
    @GetMapping(value = "/mail")
    public Object mail(Date btime, Date etime, @ApiIgnore @AuthenticationPrincipal Principal principal) throws CustomException {
        return new Result(ResultCode.SUCCESS, dateAnalysisService.statMailByDate(principal, btime, etime));
    }


    @ApiOperation(value = "公司落地页每天访问统计", notes = "公司落地页每天访问统计", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "uuid", value = "公司uuid", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Date", name = "btime", value = "开始时间", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Date", name = "etime", value = "结束时间", required = true, paramType = "query")
    })
    @GetMapping(value = "/homepage")
    public Object companyHomePage(String uuid, Date btime, Date etime) throws CustomException {
        String classMethod = "com.youhome.business.controller.HomePageController.company";
        return new Result(ResultCode.SUCCESS, dateAnalysisService.statLogByBean(uuid, btime, etime, classMethod));
    }

    @ApiOperation(value = "公司二级页每天访问统计", notes = "公司二级页每天访问统计", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "uuid", value = "公司uuid", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Date", name = "btime", value = "开始时间", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Date", name = "etime", value = "结束时间", required = true, paramType = "query")
    })
    @GetMapping(value = "/secondaryhomepage")
    public Object companySecondaryHomePage(String uuid, Date btime, Date etime) throws CustomException {
        String classMethod = "com.youhome.business.controller.SecondaryHomePageController.templateData";
        return new Result(ResultCode.SUCCESS, dateAnalysisService.statLogByBean(uuid, btime, etime, classMethod));
    }

    @ApiOperation(value = "公司客户每天注册统计", notes = "公司客户每天注册统计", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "uuid", value = "公司uuid", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Date", name = "btime", value = "开始时间", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Date", name = "etime", value = "结束时间", required = true, paramType = "query")
    })
    @GetMapping(value = "/register")
    public Object register(String uuid, Date btime, Date etime) throws CustomException {
        return new Result(ResultCode.SUCCESS, dateAnalysisService.statClientRegisterCount(uuid, btime, etime));
    }

    @ApiOperation(value = "当前用户每天接口访问日志", notes = "当前用户每天接口访问日志", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Date", name = "btime", value = "开始时间", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "Date", name = "etime", value = "结束时间", required = true, paramType = "query")
    })
    @GetMapping(value = "/log")
    public Object log(Date btime, Date etime, @ApiIgnore @AuthenticationPrincipal Principal principal) throws CustomException {
        return new Result(ResultCode.SUCCESS, dateAnalysisService.statLogByBean(principal, btime, etime));
    }

}
